package com.idanchuang.component.logback.runner;

import com.idanchuang.component.logback.config.LogbackSentryConfig;
import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;

/**
 *
 * 初始化Sentry
 *
 * @author yjy
 * @date 2020/2/28 15:06
 **/
public class InitSentryRunner implements CommandLineRunner {

    private static final Logger log = LoggerFactory.getLogger(InitSentryRunner.class);

    private LogbackSentryConfig config;

    public InitSentryRunner(LogbackSentryConfig config) {
        this.config = config;
    }

    @Override
    public void run(String... args) throws Exception {
        if (config.getDsn() == null || "".equals(config.getDsn())) {
            log.warn("Will not init Sentry, Sentry config is enabled, but dsn is unassigned");
            return;
        }
        Sentry.init(config.getDsn());
        log.info("Sentry initialized with dsn: {}", config.getDsn());
    }

}
